package com.kyh.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
 
public class ConverterUtil {
 
  // JGP格式
  public static final String JPG = "jpeg";
  // GIF格式
  public static final String GIF = "gif";
  // PNG格式
  public static final String PNG = "png";
  // BMP格式
  public static final String BMP = "bmp";
  
   
  public static File converter(File imgFile,String format,File formatFile)
      throws IOException{
    BufferedImage bIMG =ImageIO.read(imgFile);
    ImageIO.write(bIMG, format, formatFile);
    return formatFile;
  }
  
  
   
  public static void main(String[] args) {
    try {
      // 转换为PNG
      ConverterUtil.converter(new File("c:\\psb.jpg"),PNG, new File("c:\\psb2.png"));
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
